258template <
class TypeBase,
typename... TypeInput>
266 typedef std::map<std::string, CreatorCallback> CallbackMap;
272 static TypeBase
create(
const std::string& _type, TypeInput... _input);
279 CallbackMap callbacks_;
296template <
class TypeBase,
typename... TypeInput>
302template <
class TypeBase,
typename... TypeInput>
303inline Factory<TypeBase, TypeInput...>::~Factory()
308template <
class TypeBase,
typename... TypeInput>
311 if (get().callbacks_.count(_type) == 1 and get().callbacks_.at(_type) != createFn)
312 throw std::runtime_error(get().getClass() +
" : For the type \"" + _type +
313 "\": Trying to register a creator but there is a different creator registered.");
315 bool reg = get().callbacks_.insert(
typename CallbackMap::value_type(_type, createFn)).second;
317 if (reg) std::cout << std::setw(31) << std::left << get().getClass() <<
" <-- registered " << _type << std::endl;
322template <
class TypeBase,
typename... TypeInput>
325 return get().callbacks_.erase(_type) == 1;
328template <
class TypeBase,
typename... TypeInput>
331 return get().callbacks_.count(_type) == 1;
334template <
class TypeBase,
typename... TypeInput>
337 typename CallbackMap::const_iterator creator_callback_it = get().callbacks_.find(_type);
339 if (creator_callback_it == get().callbacks_.end())
341 throw std::runtime_error(get().getClass() +
" : Unknown type \"" + _type +
342 "\". Possibly you tried to use an unregistered creator.");
345 return (creator_callback_it->second)(std::forward<TypeInput>(_input)...);
348template <
class TypeBase,
typename... TypeInput>
351 static Factory<TypeBase, TypeInput...> instance_;
355template <
class TypeBase,
typename... TypeInput>
358 return "Factory<class TypeBase>";
361template <
class TypeBase,
typename... TypeInput>
364 std::cout << get().getClass() <<
" address: " << &get() << std::endl;
367template <
class TypeBase,
typename... TypeInput>
370 std::cout << get().getClass() <<
" callbacks size: " << get().callbacks_.size() << std::endl;
371 for (
auto cb : get().callbacks_)
373 std::cout <<
"\t" << cb.first << std::endl;
377template <
class TypeBase,
typename... TypeInput>
380 std::list<std::string> keys;
381 for (
auto cb : get().callbacks_)
383 keys.push_back(cb.first);
Singleton template factory.
Definition: factory.h:260
static void printCallbacks()
Definition: factory.h:368
static bool registerCreator(const std::string &_type, CreatorCallback createFn)
Definition: factory.h:309
static TypeBase create(const std::string &_type, TypeInput... _input)
Definition: factory.h:335
static std::list< std::string > getRegisteredKeys()
Definition: factory.h:378
TypeBase(* CreatorCallback)(TypeInput... _input)
Definition: factory.h:263
static bool isCreatorRegistered(const std::string &_type)
Definition: factory.h:329
void operator=(Factory const &)=delete
std::string getClass() const
Definition: factory.h:356
Factory(const Factory &)=delete
static void printAddress()
Definition: factory.h:362
static bool unregisterCreator(const std::string &_type)
Definition: factory.h:323
Definition: capture_base.h:23